package org.cy.evolution.net.http.exception;

import android.content.Context;
import android.support.annotation.StringRes;

import org.cy.evolution.R;

public enum HttpStatus {

    UNKNOWN_ERROR(-1, "未知错误！"),
    NOT_FOUND(404, "请求地址未找到或不存在！"),
    CONNECTION_TIMEOUT(408, "网络连接已超时！"),
    NOT_CONNECT(499, "网络没有连接！"),
    INTERNAL_SERVER_ERROR(500, "网络服务错误！"),
    BAD_GATEWAY(502, "错误的服务网关！"),
    SERVICE_UNAVAILABLE(503, "网络服务不可用！"),
    UNEXPECTED_ERROR(700, "服务器发生意外错误！"),
    RESPONSE_PARSE_ERROR(1001, "请求响应结果解析错误！");

    private int code;
    private String msg;

    HttpStatus(int code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public int getCode() {
        return code;
    }

    public String getMsg() {
        return msg;
    }

    public static HttpStatus valueOfByCode(int code) {
        for (HttpStatus value: HttpStatus.values()) {
            if (value.getCode() == code) {
                return value;
            }
        }
        return HttpStatus.UNKNOWN_ERROR;
    }
}
